/**
 * 
 */
package com.laozhao.wintersystem;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.lang.model.element.Element;
import javax.sql.DataSource;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Node;
import org.xml.sax.SAXException;

/**
 * @author zdongmen
 *
 */
public class WSystem extends AbstractNode implements System {
	
	private String skin;
	private String version;
	
	private Splash splash;
	private Tray tray;
	private DataSource dataSource;
	private Map<String, Frame> framMap;
	private Map<String, Part> partMap;

	/**
	 * 
	 */
	public WSystem() {
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#getDataSource(java.lang.String)
	 */
	@Override
	public DataSource getDataSource(String id) {
		return dataSource;
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#getFrame(java.lang.String)
	 */
	@Override
	public Frame getFrame(String id) {		
		return framMap.get(id);
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#getPart(java.lang.String)
	 */
	@Override
	public Part getPart(String id) {
		return partMap.get(id);
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#getSkin()
	 */
	@Override
	public String getSkin() {
		return skin;
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#getSplash()
	 */
	@Override
	public Splash getSplash() {
		return splash;
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#getTray()
	 */
	@Override
	public Tray getTray() {
		return tray;
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#getVersion()
	 */
	@Override
	public String getVersion() {
		return version;
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#init(java.util.List)
	 */
	@Override
	public void init(List<Element> fileList) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#setDataSource(javax.sql.DataSource)
	 */
	@Override
	public void setDataSource(DataSource dataSource) {
		if (dataSource != null && "".equals(dataSource)) {
			this.dataSource = dataSource;
		}
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#setFrame(com.laozhao.wintersystem.Frame)
	 */
	@Override
	public void setFrame(Frame frame) {
		if (frame != null && "".equals(frame)) {
			this.framMap.put(frame.getId(), frame);
		}
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#setPart(com.laozhao.wintersystem.Part)
	 */
	@Override
	public void setPart(Part part) {
		if (part != null && "".equals(part)) {
			this.partMap.put(part.getId(), part);
		}
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#setSkin(java.lang.String)
	 */
	@Override
	public void setSkin(String skin) {
		if (skin != null && "".equals(skin)) {
			this.skin = skin ;
		}
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#setSplash(com.laozhao.wintersystem.Splash)
	 */
	@Override
	public void setSplash(Splash splash) {
		if (splash != null && "".equals(splash)) {
			this.splash = splash ;
			splash.showSplash();
		}
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#setTray(com.laozhao.wintersystem.Tray)
	 */
	@Override
	public void setTray(Tray tray) {
		if (tray != null && "".equals(tray)) {
			this.tray = tray ;
		}
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#setVersion(java.lang.String)
	 */
	@Override
	public void setVersion(String version) {
		if (version != null && "".equals(version)) {
			this.version = version ;
		}
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#star()
	 */
	@Override
	public void star() {
		if (splash != null) {
			splash.closeSplash();
		}
		for (Frame frame : framMap.values()) {
			if(frame.getVisible()){
				frame.showFrame();
			}
		}
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.System#stop()
	 */
	@Override
	public void stop() {
		

	}

	

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.BaseNode#load(org.w3c.dom.Node)
	 */
	@Override
	public void load(Node node){
		if (node != null) {
			super.load(node);
			setSkin(WSTools.getStringAttribute(node, ATTRIBUTE_SYSTEM_SKIN));
			setVersion(WSTools.getStringAttribute(node, ATTRIBUTE_SYSTEM_VERSION));
		}
	}

	/* (non-Javadoc)
	 * @see com.laozhao.wintersystem.BaseNode#setProperty(com.laozhao.wintersystem.Property)
	 */
	@Override
	public void setProperty(Property property) {
		
	}

	@Override
	public Property getProperty(String name) {
		// TODO Auto-generated method stub
		return null;
	}

}
